//
//  GDShowTrainsDataController.m
//  GraduationDesign
//
//  Created by JiaKang.Zhong on 16/2/19.
//  Copyright © 2016年 JiaKang.Zhong. All rights reserved.
//

#import "GDShowTrainsDataController.h"
#import "GDTrainModelCell.h"

@interface GDShowTrainsDataController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong) UITableView * tableView;
@end

@implementation GDShowTrainsDataController

-(UITableView *) tableView{
    if (!_tableView) {
        CGRect rectSize = CGRectMake(0, 44, GDScreenSize.size.width ,GDScreenSize.size.height  - 44);
        _tableView = [[UITableView alloc] initWithFrame:rectSize style:UITableViewStylePlain];
        _tableView.backgroundColor =[UIColor clearColor];
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.showsVerticalScrollIndicator = NO;
        [self.view addSubview:_tableView];
    }
    return _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.view.backgroundColor = [UIColor whiteColor];
   [self setUpViewBG];
    [self setNavigatorControl];
}

- (void) setNavigatorControl
{
    CGRect aScreenRect = [[UIScreen mainScreen] bounds];

    //创建navbar
    UINavigationBar *nav = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, aScreenRect.size.width, 66)];
    nav.backgroundColor = [UIColor colorWithRed:42/ 255.0 green:137/255.0 blue:215/255.0 alpha:1];
    //创建navbaritem
    UINavigationItem *NavTitle =  [[UINavigationItem alloc] initWithTitle: @"查询结果"];
    
    [nav pushNavigationItem:NavTitle animated:YES];
    [self.view addSubview:nav];
    //创建barbutton 创建系统样式的
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"left-cross"] style:UIBarButtonItemStylePlain target:self action:@selector(rtnExit)];
    
    
    //设置barbutton
    NavTitle.leftBarButtonItem = backItem;
    [nav setItems:[NSArray arrayWithObject:NavTitle]];
}

- (void) rtnExit{
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark ****************创建完成按钮
- (void) setChildView{
    
}


-(BOOL)prefersStatusBarHidden{
    return YES;
}


-(void)setUpViewBG{
    
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:self.view.frame];
    NSString * strFile = [[NSBundle mainBundle] pathForResource:@"trainBG.jpg" ofType:nil];
    UIImage * image = [UIImage imageWithContentsOfFile:strFile];
    imageView.image = image;
    imageView.alpha = 0.6;
    [self.view addSubview:imageView];
    [self.view sendSubviewToBack:imageView];
}



#pragma mark 每一组多少行
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.trainsArrayModel.count;
}


#pragma mark 每一cell的内容
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    GDTrainModelCell * cell = [GDTrainModelCell cellWithTableView:tableView and:indexPath];
    GDTrainViewModel * viewModel =  self.trainsArrayModel[indexPath.row];
    cell.viewModel = viewModel;
    return cell;
}

#pragma mark 每一行的行高  tableView 先加载高度，在加载内容
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return GDSHOWTABLEVIEWCELLHEIGHT;
}


#pragma mark 开始滚动结束第一响应者
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    [self.view endEditing:YES];
    
}



@end
